<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Master React C03.01 动态组件</title>
    <script src="https://cdn.bootcss.com/react/16.2.0/umd/react.production.min.js"></script>
    <script src="https://cdn.bootcss.com/react-dom/16.2.0/umd/react-dom.production.min.js"></script>
    <script src="https://cdn.bootcss.com/babel-standalone/6.26.0/babel.min.js"></script>

    <link href="https://cdn.bootcss.com/highlight.js/9.12.0/styles/vs2015.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js"></script>

    <script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
<div id="root"></div>
<p>代码</p>
<pre><code class="js">    ReactDOM.render(
        < h1 >欢迎使用React!< /h1>,
        document.getElementById('example')
    );
</code>
<script type="text/babel">
    class UserRow extends React.Component{
        render(){
            return (
                <tr>
                    <td>{this.props.user.userName}</td>
                    <td>
                        <a href={'mailto:'+this.props.user.email}>
                            {this.props.user.email}
                        </a>
                    </td>
                </tr>
            );
        }
    }

    class UserList extends React.Component{
        getDefaultProps() {
            return {
                users: [
                    {
                        id: 1,
                        userName: 'RyanVice',
                        email: 'ryan@vicesoftware.com'
                    },
                    {
                        id: 2,
                        userName: 'AdamHorton',
                        email: 'digitalicarus@gmail.com'
                    }]
            };
        }
        constructor(){
            super();
            this.state = this.getDefaultProps();
        }
        render(){
            var users = this.state.users.map(
                function(user) {
                    return (
                        <UserRow user={user}
                                 key={user.id}/>)
                });
            return (
                <table>
                    <tr>
                        <th>User Name</th>
                        <th>Email Address</th>
                    </tr>
                    {users}
                </table>
            );
        }
    }

    ReactDOM.render(
        <UserList/>
        ,document.getElementById('root')
    );
</script>

</body>
</html>